' Alot of the information contained inside this file was originally
' obtained from ALT.WINSOCK.PROGRAMMING and most of it has since been
' modified in some way.
'
'Disclaimer: This file is public domain, updated periodically by
' Topaz, SigSegV@mail.utexas.edu, Use it at your own risk.
' Neither myself(Topaz) or anyone related to alt.programming.winsock
' may be held liable for its use, or misuse.
'
'Declare check Aug 27, 1996. (Topaz, SigSegV@mail.utexas.edu)
' All 16 bit declarations appear correct, even the odd ones that
' pass longs inplace of in_addr and char buffers. 32 bit functions
' also appear correct. Some are declared to return integers instead of
' longs (breaking MS's rules.) however after testing these functions I
' have come to the conclusion that they do not work properly when declared
' following MS's rules.
'
'NOTES:
' (1) I have never used WS_SELECT (select), therefore I must warn that I do
' not know if fd_set and timeval are properly defined.
' (2) Alot of the functions are declared with "buf as any", when calling these
' functions you may either pass strings, byte arrays or UDT's. For 32bit I
' I recommend Byte arrays and the use of memcopy to copy the data back out
' (3) The async functions (wsaAsync*) require the use of a message hook or
' message window control to capture messages sent by the winsock stack. This
' is not to be confused with a CallBack control, The only function that uses
' callbacks is WSASetBlockingHook()
' (4) Alot of "helper" functions are provided in the file for various things
' before attempting to figure out how to call a function, look and see if
' there is already a helper function for it.
' (5) Data types (hostent etc) have kept there 16bit definitions, even under 32bit
' windows due to the problem of them not working when redfined following the
' suggested rules.
Option Explicit
Public Const FD_SETSIZE = 64
Type fd_set
fd_count As Integer
fd_array(FD_SETSIZE) As Integer
End Type
Type timeval
tv_sec As Long
tv_usec As Long
End Type
Type HostEnt
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Public Const hostent_size = 16
Type servent
s_name As Long
s_aliases As Long
s_port As Integer
s_proto As Long
End Type
Public Const servent_size = 14
Type protoent
p_name As Long
p_aliases As Long
p_proto As Integer
End Type
Public Const protoent_size = 10
Public Const IPPROTO_TCP = 6
Public Const IPPROTO_UDP = 17
Public Const INADDR_NONE = &HFFFFFFFF
Public Const INADDR_ANY = &H0
Type sockaddr
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
Public Const sockaddr_size = 16
Public saZero As sockaddr
Public Const WSA_DESCRIPTIONLEN = 256
Public Const WSA_DescriptionSize = WSA_DESCRIPTIONLEN + 1
Public Const WSA_SYS_STATUS_LEN = 128
Public Const WSA_SysStatusSize = WSA_SYS_STATUS_LEN + 1
Type WSADataType
wVersion As Integer
wHighVersion As Integer
szDescription As String * WSA_DescriptionSize
szSystemStatus As String * WSA_SysStatusSize
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Public Const INVALID_SOCKET = -1
Public Const SOCKET_ERROR = -1
Public Const SOCK_STREAM = 1
Public Const SOCK_DGRAM = 2
Public Const MAXGETHOSTSTRUCT = 1024
Public Const AF_INET = 2
Public Const PF_INET = 2
Type LingerType
l_onoff As Integer
l_linger As Integer
End Type
' Windows Sockets definitions of regular Microsoft C error constants
Global Const WSAEINTR = 10004
Global Const WSAEBADF = 10009
Global Const WSAEACCES = 10013
Global Const WSAEFAULT = 10014
Global Const WSAEINVAL = 10022
Global Const WSAEMFILE = 10024
' Windows Sockets definitions of regular Berkeley error constants
Global Const WSAEWOULDBLOCK = 10035
Global Const WSAEINPROGRESS = 10036
Global Const WSAEALREADY = 10037
Global Const WSAENOTSOCK = 10038
Global Const WSAEDESTADDRREQ = 10039
Global Const WSAEMSGSIZE = 10040
Global Const WSAEPROTOTYPE = 10041
Global Const WSAENOPROTOOPT = 10042
Global Const WSAEPROTONOSUPPORT = 10043
Global Const WSAESOCKTNOSUPPORT = 10044
Global Const WSAEOPNOTSUPP = 10045
Global Const WSAEPFNOSUPPORT = 10046
Global Const WSAEAFNOSUPPORT = 10047
Global Const WSAEADDRINUSE = 10048
Global Const WSAEADDRNOTAVAIL = 10049
Global Const WSAENETDOWN = 10050
Global Const WSAENETUNREACH = 10051
Global Const WSAENETRESET = 10052
Global Const WSAECONNABORTED = 10053
Global Const WSAECONNRESET = 10054
Global Const WSAENOBUFS = 10055
Global Const WSAEISCONN = 10056
Global Const WSAENOTCONN = 10057
Global Const WSAESHUTDOWN = 10058
Global Const WSAETOOMANYREFS = 10059
Global Const WSAETIMEDOUT = 10060
Global Const WSAECONNREFUSED = 10061
Global Const WSAELOOP = 10062
Global Const WSAENAMETOOLONG = 10063
Global Const WSAEHOSTDOWN = 10064
Global Const WSAEHOSTUNREACH = 10065
Global Const WSAENOTEMPTY = 10066
Global Const WSAEPROCLIM = 10067
Global Const WSAEUSERS = 10068
Global Const WSAEDQUOT = 10069
Global Const WSAESTALE = 10070
Global Const WSAEREMOTE = 10071
' Extended Windows Sockets error constant definitions
Global Const WSASYSNOTREADY = 10091
Global Const WSAVERNOTSUPPORTED = 10092
Global Const WSANOTINITIALISED = 10093
Global Const WSAHOST_NOT_FOUND = 11001
Global Const WSATRY_AGAIN = 11002
Global Const WSANO_RECOVERY = 11003
Global Const WSANO_DATA = 11004
Global Const WSANO_ADDRESS = 11004
'---ioctl Constants
Public Const FIONREAD = &H8004667F
Public Const FIONBIO = &H8004667E
Public Const FIOASYNC = &H8004667D
#If Win16 Then
'---Windows System functions
Public Declare Function PostMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Integer
Public Declare Sub MemCopy Lib "Kernel" Alias "hmemcpy" (Dest As Any, Src As Any, ByVal cb&)
Public Declare Function lstrlen Lib "Kernel" (ByVal lpString As Any) As Integer
'---async notification constants
Public Const SOL_SOCKET = &HFFFF
Public Const SO_LINGER = &H80
Public Const FD_READ = &H1
Public Const FD_WRITE = &H2
Public Const FD_OOB = &H4
Public Const FD_ACCEPT = &H8
Public Const FD_CONNECT = &H10
Public Const FD_CLOSE = &H20
'---SOCKET FUNCTIONS
Public Declare Function accept Lib "Winsock.dll" (ByVal s As Integer, addr As sockaddr, addrlen As Integer) As Integer
Public Declare Function bind Lib "Winsock.dll" (ByVal s As Integer, addr As sockaddr, ByVal namelen As Integer) As Integer
Public Declare Function closesocket Lib "Winsock.dll" (ByVal s As Integer) As Integer
Public Declare Function connect Lib "Winsock.dll" (ByVal s As Integer, addr As sockaddr, ByVal namelen As Integer) As Integer
Public Declare Function ioctlsocket Lib "Winsock.dll" (ByVal s As Integer, ByVal cmd As Long, argp As Long) As Integer
Public Declare Function getpeername Lib "Winsock.dll" (ByVal s As Integer, sName As sockaddr, namelen As Integer) As Integer
Public Declare Function getsockname Lib "Winsock.dll" (ByVal s As Integer, sName As sockaddr, namelen As Integer) As Integer
Public Declare Function getsockopt Lib "Winsock.dll" (ByVal s As Integer, ByVal level As Integer, ByVal optname As Integer, optval As Any, optlen As Integer) As Integer
Public Declare Function htonl Lib "Winsock.dll" (ByVal hostlong As Long) As Long
Public Declare Function htons Lib "Winsock.dll" (ByVal hostshort As Integer) As Integer
Public Declare Function inet_addr Lib "Winsock.dll" (ByVal cp As String) As Long
Public Declare Function inet_ntoa Lib "Winsock.dll" (ByVal inn As Long) As Long
Public Declare Function listen Lib "Winsock.dll" (ByVal s As Integer, ByVal backlog As Integer) A